{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-28T14:15:16.682289Z",
     "iopub.status.busy": "2024-11-28T14:15:16.680847Z",
     "iopub.status.idle": "2024-11-28T14:15:17.434555Z",
     "shell.execute_reply": "2024-11-28T14:15:17.434555Z",
     "shell.execute_reply.started": "2024-11-28T14:15:16.682289Z"
    }
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import sys\n",
    "from PIL import Image"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "source": [
    "# 数据结构"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "source": [
    "## Series\n",
    "Series是一种一维标记的数组型对象，能够保存任何数据类型(int, str, float, python object...)，包含了数据标签，称为索引index。\n",
    "- 类似一维数组的对象,index =['名字\"年龄;班级]\n",
    "- 由数据和索引组成\n",
    "  - 索引(index)在左，数据(values)在右\n",
    "  - 索引是自动创建的"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "source": [
    "### 创建series\n",
    "#### 通过list创建"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2024-11-28T14:16:21.275424Z",
     "iopub.status.busy": "2024-11-28T14:16:21.275424Z",
     "iopub.status.idle": "2024-11-28T14:16:21.303957Z",
     "shell.execute_reply": "2024-11-28T14:16:21.302957Z",
     "shell.execute_reply.started": "2024-11-28T14:16:21.275424Z"
    },
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "0    1\n1    2\n2    3\n3    4\n4    5\ndtype: int64"
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": "'行号:2，↑↑↑↑↑↑↑↑↑'"
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": "pandas.core.series.Series"
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": "'行号:3，↑↑↑↑↑↑↑↑↑'"
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": "array([1, 2, 3, 4, 5])"
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": "'行号:4，↑↑↑↑↑↑↑↑↑'"
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": "RangeIndex(start=0, stop=5, step=1)"
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": "'行号:5，↑↑↑↑↑↑↑↑↑'"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "s1 = pd.Series([1,2,3,4,5])\n",
    "display(s1,f\"行号:{sys._getframe().f_lineno}，↑↑↑↑↑↑↑↑↑\")\n",
    "display(type(s1),f\"行号:{sys._getframe().f_lineno}，↑↑↑↑↑↑↑↑↑\")\n",
    "display(s1.values,f\"行号:{sys._getframe().f_lineno}，↑↑↑↑↑↑↑↑↑\")\n",
    "display(s1.index,f\"行号:{sys._getframe().f_lineno}，↑↑↑↑↑↑↑↑↑\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 通过数组创建"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-28T14:19:41.219645Z",
     "iopub.status.busy": "2024-11-28T14:19:41.219645Z",
     "iopub.status.idle": "2024-11-28T14:19:41.240034Z",
     "shell.execute_reply": "2024-11-28T14:19:41.238903Z",
     "shell.execute_reply.started": "2024-11-28T14:19:41.219645Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "array([1, 2, 3, 4, 5])"
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": "'↑↑↑↑↑↑↑↑↑，行号:2'"
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": "0    1\n1    2\n2    3\n3    4\n4    5\ndtype: int64"
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": "'↑↑↑↑↑↑↑↑↑，行号:4'"
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": "a    1\nb    2\nc    3\nd    4\ne    5\ndtype: int64"
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": "'↑↑↑↑↑↑↑↑↑，行号:7'"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "arr1 = np.arange(1,6)\n",
    "display(arr1,f\"↑↑↑↑↑↑↑↑↑，行号:{sys._getframe().f_lineno}\")\n",
    "s2 = pd.Series(arr1)\n",
    "display(s2,f\"↑↑↑↑↑↑↑↑↑，行号:{sys._getframe().f_lineno}\")\n",
    "# 索引长度和数据长度必须相同\n",
    "s2 = pd.Series(arr1,index=['a','b','c','d','e'])\n",
    "display(s2,f\"↑↑↑↑↑↑↑↑↑，行号:{sys._getframe().f_lineno}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 通过字典创建"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-28T14:20:33.358260Z",
     "iopub.status.busy": "2024-11-28T14:20:33.358260Z",
     "iopub.status.idle": "2024-11-28T14:20:33.367066Z",
     "shell.execute_reply": "2024-11-28T14:20:33.367066Z",
     "shell.execute_reply.started": "2024-11-28T14:20:33.358260Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "name      李宁\nage       18\nclass     三班\nsex      NaN\ndtype: object"
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": "'↑↑↑↑↑↑↑↑↑，行号:3'"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "dict = {'name':'李宁','age':18,'class':'三班'}\n",
    "s3 = pd.Series(dict,index = ['name','age','class','sex'])\n",
    "display(s3,f\"↑↑↑↑↑↑↑↑↑，行号:{sys._getframe().f_lineno}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Series的基本用法"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### isnull 和 notnull 检查缺失值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-28T14:21:56.965334Z",
     "iopub.status.busy": "2024-11-28T14:21:56.964090Z",
     "iopub.status.idle": "2024-11-28T14:21:56.981797Z",
     "shell.execute_reply": "2024-11-28T14:21:56.981797Z",
     "shell.execute_reply.started": "2024-11-28T14:21:56.965334Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "name     False\nage      False\nclass    False\nsex       True\ndtype: bool"
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s3.isnull()  #判断是否为空  空就是True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-28T14:21:57.859030Z",
     "iopub.status.busy": "2024-11-28T14:21:57.859030Z",
     "iopub.status.idle": "2024-11-28T14:21:57.866467Z",
     "shell.execute_reply": "2024-11-28T14:21:57.866467Z",
     "shell.execute_reply.started": "2024-11-28T14:21:57.859030Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "name      True\nage       True\nclass     True\nsex      False\ndtype: bool"
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s3.notnull() #判断是否不为空  非空True"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 通过索引获取数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-28T14:22:32.961976Z",
     "iopub.status.busy": "2024-11-28T14:22:32.961976Z",
     "iopub.status.idle": "2024-11-28T14:22:32.981169Z",
     "shell.execute_reply": "2024-11-28T14:22:32.981015Z",
     "shell.execute_reply.started": "2024-11-28T14:22:32.961976Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "Index(['name', 'age', 'class', 'sex'], dtype='object')"
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s3.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-28T14:22:38.275108Z",
     "iopub.status.busy": "2024-11-28T14:22:38.275108Z",
     "iopub.status.idle": "2024-11-28T14:22:38.288803Z",
     "shell.execute_reply": "2024-11-28T14:22:38.288298Z",
     "shell.execute_reply.started": "2024-11-28T14:22:38.275108Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "array(['李宁', 18, '三班', nan], dtype=object)"
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s3.values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-28T14:22:50.023383Z",
     "iopub.status.busy": "2024-11-28T14:22:50.022380Z",
     "iopub.status.idle": "2024-11-28T14:22:50.028757Z",
     "shell.execute_reply": "2024-11-28T14:22:50.028757Z",
     "shell.execute_reply.started": "2024-11-28T14:22:50.023383Z"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\98614\\AppData\\Local\\Temp\\ipykernel_32088\\1635453558.py:2: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`\n",
      "  s3[0]\n"
     ]
    },
    {
     "data": {
      "text/plain": "'李宁'"
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 下标\n",
    "s3[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-28T14:23:07.617292Z",
     "iopub.status.busy": "2024-11-28T14:23:07.617292Z",
     "iopub.status.idle": "2024-11-28T14:23:07.628288Z",
     "shell.execute_reply": "2024-11-28T14:23:07.628288Z",
     "shell.execute_reply.started": "2024-11-28T14:23:07.617292Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "18"
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 标签名\n",
    "s3['age']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-28T14:23:13.101011Z",
     "iopub.status.busy": "2024-11-28T14:23:13.099498Z",
     "iopub.status.idle": "2024-11-28T14:23:13.119516Z",
     "shell.execute_reply": "2024-11-28T14:23:13.119516Z",
     "shell.execute_reply.started": "2024-11-28T14:23:13.101011Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "name    李宁\nage     18\ndtype: object"
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 选取多个\n",
    "s3[['name','age']]  # s3[[0,1]] "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-28T14:23:18.389297Z",
     "iopub.status.busy": "2024-11-28T14:23:18.389297Z",
     "iopub.status.idle": "2024-11-28T14:23:18.401596Z",
     "shell.execute_reply": "2024-11-28T14:23:18.401090Z",
     "shell.execute_reply.started": "2024-11-28T14:23:18.389297Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "age      18\nclass    三班\ndtype: object"
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 切片 切片下标是从0开始的\n",
    "s3[1:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-28T14:23:25.664908Z",
     "iopub.status.busy": "2024-11-28T14:23:25.664908Z",
     "iopub.status.idle": "2024-11-28T14:23:25.685988Z",
     "shell.execute_reply": "2024-11-28T14:23:25.684984Z",
     "shell.execute_reply.started": "2024-11-28T14:23:25.664908Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "name     李宁\nage      18\nclass    三班\ndtype: object"
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#标签切片 包含末端数据\n",
    "s3['name':'class']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-28T14:23:39.317239Z",
     "iopub.status.busy": "2024-11-28T14:23:39.317239Z",
     "iopub.status.idle": "2024-11-28T14:23:39.328800Z",
     "shell.execute_reply": "2024-11-28T14:23:39.328800Z",
     "shell.execute_reply.started": "2024-11-28T14:23:39.317239Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "d    4\ne    5\ndtype: int64"
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#布尔索引\n",
    "s2[s2>3]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 索引与数据的对应关系不被运算结果影响"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-28T14:23:56.320905Z",
     "iopub.status.busy": "2024-11-28T14:23:56.320905Z",
     "iopub.status.idle": "2024-11-28T14:23:56.333228Z",
     "shell.execute_reply": "2024-11-28T14:23:56.333228Z",
     "shell.execute_reply.started": "2024-11-28T14:23:56.320905Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "a    1\nb    2\nc    3\nd    4\ne    5\ndtype: int64"
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-28T14:24:01.714217Z",
     "iopub.status.busy": "2024-11-28T14:24:01.714217Z",
     "iopub.status.idle": "2024-11-28T14:24:01.728354Z",
     "shell.execute_reply": "2024-11-28T14:24:01.727354Z",
     "shell.execute_reply.started": "2024-11-28T14:24:01.714217Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "a    3\nb    4\nc    5\nd    6\ne    7\ndtype: int64"
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s2+2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-28T14:24:07.168977Z",
     "iopub.status.busy": "2024-11-28T14:24:07.167695Z",
     "iopub.status.idle": "2024-11-28T14:24:07.183509Z",
     "shell.execute_reply": "2024-11-28T14:24:07.183509Z",
     "shell.execute_reply.started": "2024-11-28T14:24:07.168977Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "a    False\nb    False\nc     True\nd     True\ne     True\ndtype: bool"
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s2>2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### name属性"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-28T14:24:28.492961Z",
     "iopub.status.busy": "2024-11-28T14:24:28.492456Z",
     "iopub.status.idle": "2024-11-28T14:24:28.505781Z",
     "shell.execute_reply": "2024-11-28T14:24:28.505781Z",
     "shell.execute_reply.started": "2024-11-28T14:24:28.492961Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "year\na    1\nb    2\nc    3\nd    4\ne    5\nName: temp, dtype: int64"
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s2.name = 'temp'  #对象名\n",
    "s2.index.name = 'year'  #对象索引名\n",
    "s2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 其他"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-28T14:24:46.875397Z",
     "iopub.status.busy": "2024-11-28T14:24:46.875397Z",
     "iopub.status.idle": "2024-11-28T14:24:46.893924Z",
     "shell.execute_reply": "2024-11-28T14:24:46.893924Z",
     "shell.execute_reply.started": "2024-11-28T14:24:46.875397Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "year\na    1\nb    2\nc    3\nName: temp, dtype: int64"
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s2.head(3)  #不传参数的话，默认前5行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-28T14:24:52.587588Z",
     "iopub.status.busy": "2024-11-28T14:24:52.587588Z",
     "iopub.status.idle": "2024-11-28T14:24:52.602533Z",
     "shell.execute_reply": "2024-11-28T14:24:52.602028Z",
     "shell.execute_reply.started": "2024-11-28T14:24:52.587588Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "year\nd    4\ne    5\nName: temp, dtype: int64"
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s2.tail(2)  #不传参数的话，尾部默认后5行"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## DataFrame\n",
    "DataFrame是一个表格型的数据结构，它含有一组有序的列，每列可以是不同类型的值。DataFrame既有行索引也有列索引，它可以被看做是由Series组成的字典（共用同一个索引)，数据是以二维结构存放的。\n",
    "- 类似多维数组/表格数据(如，excel,R中的data.frame)\n",
    "- 每列数据可以是不同的类型\n",
    "- 索引包括列索引和行索引\n",
    "    - <img alt=\"Image Description\" height=\"300\" src=\"https://cdn.nlark.com/yuque/0/2021/png/1862552/1631864834206-daf1101a-7469-4d96-b535-77c455885904.png\" width=\"300\"/>\n",
    "- axis=0和axis=1的概念\n",
    "    - <img alt=\"Image Description\" height=\"300\" src=\"https://cdn.nlark.com/yuque/0/2021/png/1862552/1631950193830-b5f92731-6802-4673-b619-e6595d6ca892.png\" width=\"300\"/>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 创建DataFrame"
   ]
  },
  {
   "cell_type": "markdown",
   "source": [
    "#### 字典类\n",
    "数组、列表或元组构成的字典构造dataframe"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "outputs": [
    {
     "data": {
      "text/plain": "   a  b   c\n0  1  5   9\n1  2  6  10\n2  3  7  11\n3  4  8  12",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>a</th>\n      <th>b</th>\n      <th>c</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1</td>\n      <td>5</td>\n      <td>9</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2</td>\n      <td>6</td>\n      <td>10</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>3</td>\n      <td>7</td>\n      <td>11</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>4</td>\n      <td>8</td>\n      <td>12</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 数组、列表或元组构成的字典构造dataframe\n",
    "# 构造一个字典\n",
    "data = {'a':[1,2,3,4],\n",
    "        'b':(5,6,7,8),\n",
    "       'c':np.arange(9,13)}\n",
    "#构造dataframe\n",
    "frame = pd.DataFrame(data)\n",
    "frame"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "outputs": [
    {
     "data": {
      "text/plain": "RangeIndex(start=0, stop=4, step=1)"
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#index属性查看行索引\n",
    "frame.index"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "outputs": [
    {
     "data": {
      "text/plain": "Index(['a', 'b', 'c'], dtype='object')"
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#columns属性查看列索引\n",
    "frame.columns"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "outputs": [
    {
     "data": {
      "text/plain": "array([[ 1,  5,  9],\n       [ 2,  6, 10],\n       [ 3,  7, 11],\n       [ 4,  8, 12]])"
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#values属性查看值\n",
    "frame.values"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "outputs": [
    {
     "data": {
      "text/plain": "   a  b   c\nA  1  5   9\nB  2  6  10\nC  3  7  11\nD  4  8  12",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>a</th>\n      <th>b</th>\n      <th>c</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>A</th>\n      <td>1</td>\n      <td>5</td>\n      <td>9</td>\n    </tr>\n    <tr>\n      <th>B</th>\n      <td>2</td>\n      <td>6</td>\n      <td>10</td>\n    </tr>\n    <tr>\n      <th>C</th>\n      <td>3</td>\n      <td>7</td>\n      <td>11</td>\n    </tr>\n    <tr>\n      <th>D</th>\n      <td>4</td>\n      <td>8</td>\n      <td>12</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#指定index\n",
    "frame = pd.DataFrame(data,index=['A','B','C','D'])\n",
    "frame"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "outputs": [
    {
     "data": {
      "text/plain": "   a  b   c    d\nA  1  5   9  NaN\nB  2  6  10  NaN\nC  3  7  11  NaN\nD  4  8  12  NaN",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>a</th>\n      <th>b</th>\n      <th>c</th>\n      <th>d</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>A</th>\n      <td>1</td>\n      <td>5</td>\n      <td>9</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>B</th>\n      <td>2</td>\n      <td>6</td>\n      <td>10</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>C</th>\n      <td>3</td>\n      <td>7</td>\n      <td>11</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>D</th>\n      <td>4</td>\n      <td>8</td>\n      <td>12</td>\n      <td>NaN</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#指定列索引\n",
    "frame = pd.DataFrame(data,index=['A','B','C','D'],columns=['a','b','c','d'])\n",
    "frame"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "Series构成的字典构造dataframe"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "outputs": [
    {
     "data": {
      "text/plain": "   a    b\n0  0  3.0\n1  1  4.0\n2  2  NaN",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>a</th>\n      <th>b</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>0</td>\n      <td>3.0</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>1</td>\n      <td>4.0</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>2</td>\n      <td>NaN</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Series构成的字典构造dataframe\n",
    "pd1 = pd.DataFrame({'a':pd.Series(np.arange(3)),\n",
    "                   'b':pd.Series(np.arange(3,5))})\n",
    "pd1\n",
    "# b列是浮点型，是因为有个NAN值，会把这一列变为浮点型"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "字典构成的字典构造dataframe"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "outputs": [
    {
     "data": {
      "text/plain": "          a  b    c\napple   3.6  3  3.2\nbanana  5.6  5  NaN",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>a</th>\n      <th>b</th>\n      <th>c</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>apple</th>\n      <td>3.6</td>\n      <td>3</td>\n      <td>3.2</td>\n    </tr>\n    <tr>\n      <th>banana</th>\n      <td>5.6</td>\n      <td>5</td>\n      <td>NaN</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#字典构成的字典构造dataframe\n",
    "#字典嵌套\n",
    "data1 = {\n",
    "    'a':{'apple':3.6,'banana':5.6},\n",
    "    'b':{'apple':3,'banana':5},\n",
    "    'c':{'apple':3.2}\n",
    "}\n",
    "pd2 = pd.DataFrame(data1)\n",
    "pd2"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "#### 列表类\n",
    "2D ndarray 构造dataframe"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "outputs": [
    {
     "data": {
      "text/plain": "   0   1   2\n0  0   1   2\n1  3   4   5\n2  6   7   8\n3  9  10  11",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>0</th>\n      <th>1</th>\n      <th>2</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>0</td>\n      <td>1</td>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>3</td>\n      <td>4</td>\n      <td>5</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>6</td>\n      <td>7</td>\n      <td>8</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>9</td>\n      <td>10</td>\n      <td>11</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#构造二维数组对象\n",
    "arr1 = np.arange(12).reshape(4,3)\n",
    "frame1 = pd.DataFrame(arr1)\n",
    "frame1"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "字典构成的列表构造dataframe"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "outputs": [
    {
     "data": {
      "text/plain": "   apple  banana\n0    3.6     5.6\n1    3.0     5.0\n2    3.2     NaN",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>apple</th>\n      <th>banana</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>3.6</td>\n      <td>5.6</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>3.0</td>\n      <td>5.0</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>3.2</td>\n      <td>NaN</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "l1 = [{'apple':3.6,'banana':5.6},{'apple':3,'banana':5},{'apple':3.2}]\n",
    "pd3 = pd.DataFrame(l1)\n",
    "pd3"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "Series构成的列表构造dataframe"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "outputs": [
    {
     "data": {
      "text/plain": "          0         1         2\n0  0.842678  0.586540  0.256119\n1  0.361330  0.241262       NaN",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>0</th>\n      <th>1</th>\n      <th>2</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>0.842678</td>\n      <td>0.586540</td>\n      <td>0.256119</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>0.361330</td>\n      <td>0.241262</td>\n      <td>NaN</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "l2 = [pd.Series(np.random.rand(3)),pd.Series(np.random.rand(2))]\n",
    "pd4 = pd.DataFrame(l2)\n",
    "pd4"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "### DataFrame的基本用法"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "outputs": [
    {
     "data": {
      "text/plain": "   A  B  C\na  0  1  2\nc  3  4  5\nb  6  7  8",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>A</th>\n      <th>B</th>\n      <th>C</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>a</th>\n      <td>0</td>\n      <td>1</td>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>c</th>\n      <td>3</td>\n      <td>4</td>\n      <td>5</td>\n    </tr>\n    <tr>\n      <th>b</th>\n      <td>6</td>\n      <td>7</td>\n      <td>8</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd5 = pd.DataFrame(np.arange(9).reshape(3,3),index=['a','c','b'],columns=['A','B','C'])\n",
    "pd5"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "outputs": [
    {
     "data": {
      "text/plain": "   a  c  b\nA  0  3  6\nB  1  4  7\nC  2  5  8",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>a</th>\n      <th>c</th>\n      <th>b</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>A</th>\n      <td>0</td>\n      <td>3</td>\n      <td>6</td>\n    </tr>\n    <tr>\n      <th>B</th>\n      <td>1</td>\n      <td>4</td>\n      <td>7</td>\n    </tr>\n    <tr>\n      <th>C</th>\n      <td>2</td>\n      <td>5</td>\n      <td>8</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#和numpy一样 进行转置   行与列进行转置\n",
    "pd5.T"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "outputs": [
    {
     "data": {
      "text/plain": "a    0\nc    3\nb    6\nName: A, dtype: int64"
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 通过列索引获取列数据（Series类型）\n",
    "pd5['A']"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "outputs": [
    {
     "data": {
      "text/plain": "pandas.core.series.Series"
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(pd5['A'])"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "outputs": [
    {
     "data": {
      "text/plain": "   A  B  C  D\na  0  1  2  9\nc  3  4  5  9\nb  6  7  8  9",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>A</th>\n      <th>B</th>\n      <th>C</th>\n      <th>D</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>a</th>\n      <td>0</td>\n      <td>1</td>\n      <td>2</td>\n      <td>9</td>\n    </tr>\n    <tr>\n      <th>c</th>\n      <td>3</td>\n      <td>4</td>\n      <td>5</td>\n      <td>9</td>\n    </tr>\n    <tr>\n      <th>b</th>\n      <td>6</td>\n      <td>7</td>\n      <td>8</td>\n      <td>9</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 增加列数据\n",
    "pd5['D'] = 9\n",
    "pd5"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "outputs": [
    {
     "data": {
      "text/plain": "   A  B  C  D\na  0  1  2  1\nc  3  4  5  2\nb  6  7  8  3",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>A</th>\n      <th>B</th>\n      <th>C</th>\n      <th>D</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>a</th>\n      <td>0</td>\n      <td>1</td>\n      <td>2</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>c</th>\n      <td>3</td>\n      <td>4</td>\n      <td>5</td>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>b</th>\n      <td>6</td>\n      <td>7</td>\n      <td>8</td>\n      <td>3</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 增加列数据\n",
    "pd5['D'] = [1,2,3]\n",
    "pd5"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "outputs": [
    {
     "data": {
      "text/plain": "   A  B  C\na  0  1  2\nc  3  4  5\nb  6  7  8",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>A</th>\n      <th>B</th>\n      <th>C</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>a</th>\n      <td>0</td>\n      <td>1</td>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>c</th>\n      <td>3</td>\n      <td>4</td>\n      <td>5</td>\n    </tr>\n    <tr>\n      <th>b</th>\n      <td>6</td>\n      <td>7</td>\n      <td>8</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 删除列\n",
    "del(pd5['D'])\n",
    "pd5"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "# 索引操作\n",
    "## 索引对象Index\n",
    "Series和DataFrame中的索引都是Index对象"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.indexes.base.Index'>\n"
     ]
    }
   ],
   "source": [
    "ps1 = pd.Series(range(5),index=['a','b','c','d','e'])\n",
    "print(type(ps1.index))"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "outputs": [
    {
     "data": {
      "text/plain": "a    0\nb    1\nc    2\nd    3\ne    4\ndtype: int64"
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ps1"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "outputs": [
    {
     "data": {
      "text/plain": "   A  B  C\na  0  1  2\nb  3  4  5\nc  6  7  8",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>A</th>\n      <th>B</th>\n      <th>C</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>a</th>\n      <td>0</td>\n      <td>1</td>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>b</th>\n      <td>3</td>\n      <td>4</td>\n      <td>5</td>\n    </tr>\n    <tr>\n      <th>c</th>\n      <td>6</td>\n      <td>7</td>\n      <td>8</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd1 = pd.DataFrame(np.arange(9).reshape(3,3),index = ['a','b','c'],columns = ['A','B','C'])\n",
    "pd1"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "Index does not support mutable operations",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mTypeError\u001B[0m                                 Traceback (most recent call last)",
      "Cell \u001B[1;32mIn[86], line 2\u001B[0m\n\u001B[0;32m      1\u001B[0m \u001B[38;5;66;03m# 索引对象不可变，保证了数据的安全\u001B[39;00m\n\u001B[1;32m----> 2\u001B[0m \u001B[43mpd1\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mindex\u001B[49m\u001B[43m[\u001B[49m\u001B[38;5;241;43m1\u001B[39;49m\u001B[43m]\u001B[49m \u001B[38;5;241m=\u001B[39m \u001B[38;5;241m2\u001B[39m\n",
      "File \u001B[1;32mD:\\soft_install\\anaconda\\anaconda3\\envs\\QiXiaoFu\\lib\\site-packages\\pandas\\core\\indexes\\base.py:5371\u001B[0m, in \u001B[0;36mIndex.__setitem__\u001B[1;34m(self, key, value)\u001B[0m\n\u001B[0;32m   5369\u001B[0m \u001B[38;5;129m@final\u001B[39m\n\u001B[0;32m   5370\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m \u001B[38;5;21m__setitem__\u001B[39m(\u001B[38;5;28mself\u001B[39m, key, value) \u001B[38;5;241m-\u001B[39m\u001B[38;5;241m>\u001B[39m \u001B[38;5;28;01mNone\u001B[39;00m:\n\u001B[1;32m-> 5371\u001B[0m     \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mTypeError\u001B[39;00m(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mIndex does not support mutable operations\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n",
      "\u001B[1;31mTypeError\u001B[0m: Index does not support mutable operations"
     ]
    }
   ],
   "source": [
    "# 索引对象不可变，保证了数据的安全\n",
    "pd1.index[1] = 2"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "常见的Index种类\n",
    "● Index，索引\n",
    "● Int64Index，整数索引\n",
    "● MultiIndex，层级索引\n",
    "● DatetimeIndex，时间戳类型"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## Series索引\n",
    "index 指定行索引名"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 131,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a    0\n",
      "b    1\n",
      "c    2\n",
      "d    3\n",
      "e    4\n",
      "dtype: int64\n"
     ]
    }
   ],
   "source": [
    "ser_obj = pd.Series(range(5), index = ['a', 'b', 'c', 'd', 'e'])\n",
    "print(ser_obj.head())"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "行索引"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "print(ser_obj['b'])"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "print(ser_obj[2])"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "切片索引\n",
    "注意，按索引名切片操作时，是包含终止索引的。"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "print(ser_obj[1:3])\n",
    "print(ser_obj['b':'d'])"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "不连续索引"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "display(ser_obj[[0, 2, 4]])\n",
    "display(ser_obj[['a', 'e']])"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "布尔索引"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "ser_bool = ser_obj > 2\n",
    "display(ser_bool)\n",
    "display(ser_obj[ser_bool])\n",
    "display(ser_obj[ser_obj > 2])"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## DataFrame索引\n",
    "columns 指定列索引名"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "          a         b         c         d\n",
      "0  0.203998 -0.218377  0.431281  0.488778\n",
      "1  1.061244 -0.077600 -1.745808  0.987524\n",
      "2  0.015731  1.262258 -0.824925 -0.474100\n",
      "3 -1.239724 -0.439741 -0.463484  0.912487\n",
      "4 -0.366651 -1.382506 -0.319084  1.042559\n"
     ]
    }
   ],
   "source": [
    "df_obj = pd.DataFrame(np.random.randn(5,4), columns = ['a', 'b', 'c', 'd'])\n",
    "print(df_obj.head())"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "列索引"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "print(df_obj['a']) # 返回Series类型"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "不连续索引"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "print(df_obj[['a','c']])"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## 常用操作"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "ps1 = pd.Series(range(5),index=['a','b','c','d','e'])\n",
    "ps1"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "pd1 = pd.DataFrame(np.arange(9).reshape(3,3),index = ['a','b','c'],columns = ['A','B','C'])\n",
    "pd1"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 重新索引"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "#1.reindex 创建一个符合新索引的新对象\n",
    "ps2 = ps1.reindex(['a','b','c','d','e','f'])\n",
    "ps2"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "outputs": [
    {
     "data": {
      "text/plain": "     A    B    C\na  0.0  1.0  2.0\nb  3.0  4.0  5.0\nc  6.0  7.0  8.0\nd  NaN  NaN  NaN",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>A</th>\n      <th>B</th>\n      <th>C</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>a</th>\n      <td>0.0</td>\n      <td>1.0</td>\n      <td>2.0</td>\n    </tr>\n    <tr>\n      <th>b</th>\n      <td>3.0</td>\n      <td>4.0</td>\n      <td>5.0</td>\n    </tr>\n    <tr>\n      <th>c</th>\n      <td>6.0</td>\n      <td>7.0</td>\n      <td>8.0</td>\n    </tr>\n    <tr>\n      <th>d</th>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#行索引重建\n",
    "pd2 = pd1.reindex(['a','b','c','d'])\n",
    "pd2"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "outputs": [
    {
     "data": {
      "text/plain": "   C  B  A\na  2  1  0\nb  5  4  3\nc  8  7  6",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>C</th>\n      <th>B</th>\n      <th>A</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>a</th>\n      <td>2</td>\n      <td>1</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>b</th>\n      <td>5</td>\n      <td>4</td>\n      <td>3</td>\n    </tr>\n    <tr>\n      <th>c</th>\n      <td>8</td>\n      <td>7</td>\n      <td>6</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#列索引重建\n",
    "pd3 = pd1.reindex(columns = ['C','B','A'])\n",
    "pd3"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 增"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "outputs": [
    {
     "data": {
      "text/plain": "a    0\nb    1\nc    2\nd    3\ne    4\ng    9\ndtype: int64"
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ps1['g'] = 9 # 改变原数组\n",
    "ps1"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "outputs": [
    {
     "data": {
      "text/plain": "a      0\nb      1\nc      2\nd      3\ne      4\ng      9\nf    999\ndtype: int64"
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s1 = pd.Series({'f':999})\n",
    "ps3 = pd.concat([ps1,s1]) # 使用concat函数，不改变原数组\n",
    "ps3"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "outputs": [
    {
     "data": {
      "text/plain": "   A  B  C   4\na  0  1  2  10\nb  3  4  5  11\nc  6  7  8  12",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>A</th>\n      <th>B</th>\n      <th>C</th>\n      <th>4</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>a</th>\n      <td>0</td>\n      <td>1</td>\n      <td>2</td>\n      <td>10</td>\n    </tr>\n    <tr>\n      <th>b</th>\n      <td>3</td>\n      <td>4</td>\n      <td>5</td>\n      <td>11</td>\n    </tr>\n    <tr>\n      <th>c</th>\n      <td>6</td>\n      <td>7</td>\n      <td>8</td>\n      <td>12</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#增加列\n",
    "pd1[4] = [10,11,12]\n",
    "pd1"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "outputs": [
    {
     "data": {
      "text/plain": "     E  A  B  C   4\na    9  0  1  2  10\nb   99  3  4  5  11\nc  999  6  7  8  12",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>E</th>\n      <th>A</th>\n      <th>B</th>\n      <th>C</th>\n      <th>4</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>a</th>\n      <td>9</td>\n      <td>0</td>\n      <td>1</td>\n      <td>2</td>\n      <td>10</td>\n    </tr>\n    <tr>\n      <th>b</th>\n      <td>99</td>\n      <td>3</td>\n      <td>4</td>\n      <td>5</td>\n      <td>11</td>\n    </tr>\n    <tr>\n      <th>c</th>\n      <td>999</td>\n      <td>6</td>\n      <td>7</td>\n      <td>8</td>\n      <td>12</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 插入\n",
    "pd1.insert(0,'E',[9,99,999])\n",
    "pd1"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "outputs": [
    {
     "data": {
      "text/plain": "     E  A  B  C   4\na    9  0  1  2  10\nb   99  3  4  5  11\nc  999  6  7  8  12\nd    1  1  1  1   1",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>E</th>\n      <th>A</th>\n      <th>B</th>\n      <th>C</th>\n      <th>4</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>a</th>\n      <td>9</td>\n      <td>0</td>\n      <td>1</td>\n      <td>2</td>\n      <td>10</td>\n    </tr>\n    <tr>\n      <th>b</th>\n      <td>99</td>\n      <td>3</td>\n      <td>4</td>\n      <td>5</td>\n      <td>11</td>\n    </tr>\n    <tr>\n      <th>c</th>\n      <td>999</td>\n      <td>6</td>\n      <td>7</td>\n      <td>8</td>\n      <td>12</td>\n    </tr>\n    <tr>\n      <th>d</th>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#标签索引loc\n",
    "pd1.loc['d'] = [1,1,1,1,1]\n",
    "pd1"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "outputs": [
    {
     "data": {
      "text/plain": "     E  A  B  C   4\n0    9  0  1  2  10\n1   99  3  4  5  11\n2  999  6  7  8  12\n3    1  1  1  1   1\n4    6  6  6  6   6",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>E</th>\n      <th>A</th>\n      <th>B</th>\n      <th>C</th>\n      <th>4</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>9</td>\n      <td>0</td>\n      <td>1</td>\n      <td>2</td>\n      <td>10</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>99</td>\n      <td>3</td>\n      <td>4</td>\n      <td>5</td>\n      <td>11</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>999</td>\n      <td>6</td>\n      <td>7</td>\n      <td>8</td>\n      <td>12</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>6</td>\n      <td>6</td>\n      <td>6</td>\n      <td>6</td>\n      <td>6</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "row = [{'E':6,'A':6,'B':6,'C':6,4:6}]\n",
    "pd5 = pd.concat([pd1, pd.DataFrame(row)], ignore_index=True)\n",
    "#ignore_index 参数默认值为False，如果为True，会对新生成的dataframe使用新的索引（自动产生），忽略原来数据的索引。\n",
    "pd5"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 删"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "outputs": [
    {
     "data": {
      "text/plain": "a    0\nb    1\nc    2\nd    3\ne    4\ng    9\ndtype: int64"
     },
     "execution_count": 95,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ps1"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "outputs": [
    {
     "data": {
      "text/plain": "a    0\nc    2\nd    3\ne    4\ng    9\ndtype: int64"
     },
     "execution_count": 96,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "del ps1['b']\n",
    "ps1"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "outputs": [
    {
     "data": {
      "text/plain": "     E  A  B  C   4\na    9  0  1  2  10\nb   99  3  4  5  11\nc  999  6  7  8  12\nd    1  1  1  1   1",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>E</th>\n      <th>A</th>\n      <th>B</th>\n      <th>C</th>\n      <th>4</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>a</th>\n      <td>9</td>\n      <td>0</td>\n      <td>1</td>\n      <td>2</td>\n      <td>10</td>\n    </tr>\n    <tr>\n      <th>b</th>\n      <td>99</td>\n      <td>3</td>\n      <td>4</td>\n      <td>5</td>\n      <td>11</td>\n    </tr>\n    <tr>\n      <th>c</th>\n      <td>999</td>\n      <td>6</td>\n      <td>7</td>\n      <td>8</td>\n      <td>12</td>\n    </tr>\n    <tr>\n      <th>d</th>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 97,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd1"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "outputs": [
    {
     "data": {
      "text/plain": "   A  B  C   4\na  0  1  2  10\nb  3  4  5  11\nc  6  7  8  12\nd  1  1  1   1",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>A</th>\n      <th>B</th>\n      <th>C</th>\n      <th>4</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>a</th>\n      <td>0</td>\n      <td>1</td>\n      <td>2</td>\n      <td>10</td>\n    </tr>\n    <tr>\n      <th>b</th>\n      <td>3</td>\n      <td>4</td>\n      <td>5</td>\n      <td>11</td>\n    </tr>\n    <tr>\n      <th>c</th>\n      <td>6</td>\n      <td>7</td>\n      <td>8</td>\n      <td>12</td>\n    </tr>\n    <tr>\n      <th>d</th>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 98,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "del pd1['E']\n",
    "pd1"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "outputs": [
    {
     "data": {
      "text/plain": "a    0\nc    2\nd    3\ne    4\ndtype: int64"
     },
     "execution_count": 99,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#drop  删除轴上数据，产生新的对象，不改变原对象\n",
    "#删除一条\n",
    "ps6 = ps1.drop('g')\n",
    "ps6"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "outputs": [
    {
     "data": {
      "text/plain": "a    0\ne    4\ng    9\ndtype: int64"
     },
     "execution_count": 100,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#删除多条\n",
    "ps1.drop(['c','d'])"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "outputs": [
    {
     "data": {
      "text/plain": "   A  B  C   4\nb  3  4  5  11\nc  6  7  8  12\nd  1  1  1   1",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>A</th>\n      <th>B</th>\n      <th>C</th>\n      <th>4</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>b</th>\n      <td>3</td>\n      <td>4</td>\n      <td>5</td>\n      <td>11</td>\n    </tr>\n    <tr>\n      <th>c</th>\n      <td>6</td>\n      <td>7</td>\n      <td>8</td>\n      <td>12</td>\n    </tr>\n    <tr>\n      <th>d</th>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 101,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#dataframe\n",
    "#删除行\n",
    "pd1.drop('a')"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "outputs": [
    {
     "data": {
      "text/plain": "   A  B  C   4\nb  3  4  5  11\nc  6  7  8  12",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>A</th>\n      <th>B</th>\n      <th>C</th>\n      <th>4</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>b</th>\n      <td>3</td>\n      <td>4</td>\n      <td>5</td>\n      <td>11</td>\n    </tr>\n    <tr>\n      <th>c</th>\n      <td>6</td>\n      <td>7</td>\n      <td>8</td>\n      <td>12</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 102,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd1.drop(['a','d'])"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "outputs": [
    {
     "data": {
      "text/plain": "   B  C   4\na  1  2  10\nb  4  5  11\nc  7  8  12\nd  1  1   1",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>B</th>\n      <th>C</th>\n      <th>4</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>a</th>\n      <td>1</td>\n      <td>2</td>\n      <td>10</td>\n    </tr>\n    <tr>\n      <th>b</th>\n      <td>4</td>\n      <td>5</td>\n      <td>11</td>\n    </tr>\n    <tr>\n      <th>c</th>\n      <td>7</td>\n      <td>8</td>\n      <td>12</td>\n    </tr>\n    <tr>\n      <th>d</th>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 103,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#删除列\n",
    "pd1.drop('A',axis=1)  #1列  0 行"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "outputs": [
    {
     "data": {
      "text/plain": "   B  C   4\na  1  2  10\nb  4  5  11\nc  7  8  12\nd  1  1   1",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>B</th>\n      <th>C</th>\n      <th>4</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>a</th>\n      <td>1</td>\n      <td>2</td>\n      <td>10</td>\n    </tr>\n    <tr>\n      <th>b</th>\n      <td>4</td>\n      <td>5</td>\n      <td>11</td>\n    </tr>\n    <tr>\n      <th>c</th>\n      <td>7</td>\n      <td>8</td>\n      <td>12</td>\n    </tr>\n    <tr>\n      <th>d</th>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 104,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd1.drop('A',axis='columns')"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "outputs": [
    {
     "data": {
      "text/plain": "a    0\nc    2\ne    4\ng    9\ndtype: int64"
     },
     "execution_count": 105,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#inplace属性   在原对象上删除，并不会返回新的对象\n",
    "ps1.drop('d',inplace=True)\n",
    "ps1"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 改"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "outputs": [
    {
     "data": {
      "text/plain": "a    0\nc    2\ne    4\ng    9\ndtype: int64"
     },
     "execution_count": 106,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ps1"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "outputs": [
    {
     "data": {
      "text/plain": "   A  B  C   4\na  0  1  2  10\nb  3  4  5  11\nc  6  7  8  12\nd  1  1  1   1",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>A</th>\n      <th>B</th>\n      <th>C</th>\n      <th>4</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>a</th>\n      <td>0</td>\n      <td>1</td>\n      <td>2</td>\n      <td>10</td>\n    </tr>\n    <tr>\n      <th>b</th>\n      <td>3</td>\n      <td>4</td>\n      <td>5</td>\n      <td>11</td>\n    </tr>\n    <tr>\n      <th>c</th>\n      <td>6</td>\n      <td>7</td>\n      <td>8</td>\n      <td>12</td>\n    </tr>\n    <tr>\n      <th>d</th>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 107,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd1"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "outputs": [
    {
     "data": {
      "text/plain": "a    999\nc      2\ne      4\ng      9\ndtype: int64"
     },
     "execution_count": 108,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ps1['a'] = 999\n",
    "ps1"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\98614\\AppData\\Local\\Temp\\ipykernel_32088\\16043471.py:1: FutureWarning: Series.__setitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To set a value by position, use `ser.iloc[pos] = value`\n",
      "  ps1[0] = 888\n"
     ]
    },
    {
     "data": {
      "text/plain": "a    888\nc      2\ne      4\ng      9\ndtype: int64"
     },
     "execution_count": 109,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ps1[0] = 888\n",
    "ps1"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "outputs": [
    {
     "data": {
      "text/plain": "    A  B  C   4\na   9  1  2  10\nb  10  4  5  11\nc  11  7  8  12\nd  12  1  1   1",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>A</th>\n      <th>B</th>\n      <th>C</th>\n      <th>4</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>a</th>\n      <td>9</td>\n      <td>1</td>\n      <td>2</td>\n      <td>10</td>\n    </tr>\n    <tr>\n      <th>b</th>\n      <td>10</td>\n      <td>4</td>\n      <td>5</td>\n      <td>11</td>\n    </tr>\n    <tr>\n      <th>c</th>\n      <td>11</td>\n      <td>7</td>\n      <td>8</td>\n      <td>12</td>\n    </tr>\n    <tr>\n      <th>d</th>\n      <td>12</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 110,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#直接使用索引\n",
    "pd1['A'] = [9,10,11,12]\n",
    "pd1"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "outputs": [
    {
     "data": {
      "text/plain": "   A  B  C   4\na  6  1  2  10\nb  6  4  5  11\nc  6  7  8  12\nd  6  1  1   1",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>A</th>\n      <th>B</th>\n      <th>C</th>\n      <th>4</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>a</th>\n      <td>6</td>\n      <td>1</td>\n      <td>2</td>\n      <td>10</td>\n    </tr>\n    <tr>\n      <th>b</th>\n      <td>6</td>\n      <td>4</td>\n      <td>5</td>\n      <td>11</td>\n    </tr>\n    <tr>\n      <th>c</th>\n      <td>6</td>\n      <td>7</td>\n      <td>8</td>\n      <td>12</td>\n    </tr>\n    <tr>\n      <th>d</th>\n      <td>6</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 111,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#对象.列\n",
    "pd1.A = 6\n",
    "pd1"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "outputs": [
    {
     "data": {
      "text/plain": "   A  B  C   4    a\na  6  1  2  10  777\nb  6  4  5  11  777\nc  6  7  8  12  777\nd  6  1  1   1  777",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>A</th>\n      <th>B</th>\n      <th>C</th>\n      <th>4</th>\n      <th>a</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>a</th>\n      <td>6</td>\n      <td>1</td>\n      <td>2</td>\n      <td>10</td>\n      <td>777</td>\n    </tr>\n    <tr>\n      <th>b</th>\n      <td>6</td>\n      <td>4</td>\n      <td>5</td>\n      <td>11</td>\n      <td>777</td>\n    </tr>\n    <tr>\n      <th>c</th>\n      <td>6</td>\n      <td>7</td>\n      <td>8</td>\n      <td>12</td>\n      <td>777</td>\n    </tr>\n    <tr>\n      <th>d</th>\n      <td>6</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>777</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 112,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 变成增加列的操作\n",
    "pd1['a'] = 777\n",
    "pd1"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "outputs": [
    {
     "data": {
      "text/plain": "     A    B    C    4    a\na  777  777  777  777  777\nb    6    4    5   11  777\nc    6    7    8   12  777\nd    6    1    1    1  777",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>A</th>\n      <th>B</th>\n      <th>C</th>\n      <th>4</th>\n      <th>a</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>a</th>\n      <td>777</td>\n      <td>777</td>\n      <td>777</td>\n      <td>777</td>\n      <td>777</td>\n    </tr>\n    <tr>\n      <th>b</th>\n      <td>6</td>\n      <td>4</td>\n      <td>5</td>\n      <td>11</td>\n      <td>777</td>\n    </tr>\n    <tr>\n      <th>c</th>\n      <td>6</td>\n      <td>7</td>\n      <td>8</td>\n      <td>12</td>\n      <td>777</td>\n    </tr>\n    <tr>\n      <th>d</th>\n      <td>6</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>777</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 113,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#loc 标签索引\n",
    "pd1.loc['a'] =777\n",
    "pd1"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "outputs": [
    {
     "data": {
      "text/plain": "      A    B    C    4    a\na  1000  777  777  777  777\nb     6    4    5   11  777\nc     6    7    8   12  777\nd     6    1    1    1  777",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>A</th>\n      <th>B</th>\n      <th>C</th>\n      <th>4</th>\n      <th>a</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>a</th>\n      <td>1000</td>\n      <td>777</td>\n      <td>777</td>\n      <td>777</td>\n      <td>777</td>\n    </tr>\n    <tr>\n      <th>b</th>\n      <td>6</td>\n      <td>4</td>\n      <td>5</td>\n      <td>11</td>\n      <td>777</td>\n    </tr>\n    <tr>\n      <th>c</th>\n      <td>6</td>\n      <td>7</td>\n      <td>8</td>\n      <td>12</td>\n      <td>777</td>\n    </tr>\n    <tr>\n      <th>d</th>\n      <td>6</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>777</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 114,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd1.loc['a','A'] = 1000\n",
    "pd1"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 查"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "outputs": [
    {
     "data": {
      "text/plain": "a    888\nc      2\ne      4\ng      9\ndtype: int64"
     },
     "execution_count": 115,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1.行索引\n",
    "ps1"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "outputs": [
    {
     "data": {
      "text/plain": "np.int64(888)"
     },
     "execution_count": 116,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ps1['a']"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\98614\\AppData\\Local\\Temp\\ipykernel_32088\\2620876716.py:1: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`\n",
      "  ps1[0]\n"
     ]
    },
    {
     "data": {
      "text/plain": "np.int64(888)"
     },
     "execution_count": 117,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ps1[0]"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "outputs": [
    {
     "data": {
      "text/plain": "c    2\ne    4\ng    9\ndtype: int64"
     },
     "execution_count": 118,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#2.切片\n",
    "# 位置切片索引\n",
    "ps1[1:4]"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "outputs": [
    {
     "data": {
      "text/plain": "c    2\ne    4\ndtype: int64"
     },
     "execution_count": 119,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#标签切片   按照水印名切片操作  是包含终止索引的\n",
    "ps1['b':'e']"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "outputs": [
    {
     "data": {
      "text/plain": "a    888\ne      4\ndtype: int64"
     },
     "execution_count": 120,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 3.不连续索引\n",
    "ps1[['a','e']]"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\98614\\AppData\\Local\\Temp\\ipykernel_32088\\3368000493.py:1: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`\n",
      "  ps1[[0,2,3]]\n"
     ]
    },
    {
     "data": {
      "text/plain": "a    888\ne      4\ng      9\ndtype: int64"
     },
     "execution_count": 121,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ps1[[0,2,3]]"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "outputs": [
    {
     "data": {
      "text/plain": "      A    B    C    4    a\na  1000  777  777  777  777\nb     6    4    5   11  777\nc     6    7    8   12  777\nd     6    1    1    1  777",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>A</th>\n      <th>B</th>\n      <th>C</th>\n      <th>4</th>\n      <th>a</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>a</th>\n      <td>1000</td>\n      <td>777</td>\n      <td>777</td>\n      <td>777</td>\n      <td>777</td>\n    </tr>\n    <tr>\n      <th>b</th>\n      <td>6</td>\n      <td>4</td>\n      <td>5</td>\n      <td>11</td>\n      <td>777</td>\n    </tr>\n    <tr>\n      <th>c</th>\n      <td>6</td>\n      <td>7</td>\n      <td>8</td>\n      <td>12</td>\n      <td>777</td>\n    </tr>\n    <tr>\n      <th>d</th>\n      <td>6</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>777</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 122,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#dataframe\n",
    "pd1"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "outputs": [
    {
     "data": {
      "text/plain": "a    1000\nb       6\nc       6\nd       6\nName: A, dtype: int64"
     },
     "execution_count": 123,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#1.列索引\n",
    "pd1['A']"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "outputs": [
    {
     "data": {
      "text/plain": "      A    C\na  1000  777\nb     6    5\nc     6    8\nd     6    1",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>A</th>\n      <th>C</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>a</th>\n      <td>1000</td>\n      <td>777</td>\n    </tr>\n    <tr>\n      <th>b</th>\n      <td>6</td>\n      <td>5</td>\n    </tr>\n    <tr>\n      <th>c</th>\n      <td>6</td>\n      <td>8</td>\n    </tr>\n    <tr>\n      <th>d</th>\n      <td>6</td>\n      <td>1</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 124,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#取多列\n",
    "pd1[['A','C']]"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "outputs": [
    {
     "data": {
      "text/plain": "np.int64(1000)"
     },
     "execution_count": 125,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#选取一个值\n",
    "pd1['A']['a']"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "outputs": [
    {
     "data": {
      "text/plain": "      A    B    C    4    a\na  1000  777  777  777  777\nb     6    4    5   11  777",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>A</th>\n      <th>B</th>\n      <th>C</th>\n      <th>4</th>\n      <th>a</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>a</th>\n      <td>1000</td>\n      <td>777</td>\n      <td>777</td>\n      <td>777</td>\n      <td>777</td>\n    </tr>\n    <tr>\n      <th>b</th>\n      <td>6</td>\n      <td>4</td>\n      <td>5</td>\n      <td>11</td>\n      <td>777</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 126,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#2.切片\n",
    "pd1[:2]  #获取行"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## 布尔索引"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 138,
   "outputs": [
    {
     "data": {
      "text/plain": "   Python  Math   En\nA      41    89  150\nB     131   107  113\nC     105   110   85\nD     120   107  106\nE      42    28   41\nF      64    32   28\nH     121    93   99\nI      42    83   70\nJ      13    80    2\nK      87    89  116",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Python</th>\n      <th>Math</th>\n      <th>En</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>A</th>\n      <td>41</td>\n      <td>89</td>\n      <td>150</td>\n    </tr>\n    <tr>\n      <th>B</th>\n      <td>131</td>\n      <td>107</td>\n      <td>113</td>\n    </tr>\n    <tr>\n      <th>C</th>\n      <td>105</td>\n      <td>110</td>\n      <td>85</td>\n    </tr>\n    <tr>\n      <th>D</th>\n      <td>120</td>\n      <td>107</td>\n      <td>106</td>\n    </tr>\n    <tr>\n      <th>E</th>\n      <td>42</td>\n      <td>28</td>\n      <td>41</td>\n    </tr>\n    <tr>\n      <th>F</th>\n      <td>64</td>\n      <td>32</td>\n      <td>28</td>\n    </tr>\n    <tr>\n      <th>H</th>\n      <td>121</td>\n      <td>93</td>\n      <td>99</td>\n    </tr>\n    <tr>\n      <th>I</th>\n      <td>42</td>\n      <td>83</td>\n      <td>70</td>\n    </tr>\n    <tr>\n      <th>J</th>\n      <td>13</td>\n      <td>80</td>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>K</th>\n      <td>87</td>\n      <td>89</td>\n      <td>116</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 138,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(\n",
    "    np.random.randint(0, 151, size=(10, 3)),\n",
    "    index=list(\"ABCDEFHIJK\"),\n",
    "    columns=[\"Python\", \"Math\", \"En\"],\n",
    ")\n",
    "df"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 139,
   "outputs": [
    {
     "data": {
      "text/plain": "   Python  Math   En\nB     131   107  113\nC     105   110   85\nD     120   107  106\nH     121    93   99\nK      87    89  116",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Python</th>\n      <th>Math</th>\n      <th>En</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>B</th>\n      <td>131</td>\n      <td>107</td>\n      <td>113</td>\n    </tr>\n    <tr>\n      <th>C</th>\n      <td>105</td>\n      <td>110</td>\n      <td>85</td>\n    </tr>\n    <tr>\n      <th>D</th>\n      <td>120</td>\n      <td>107</td>\n      <td>106</td>\n    </tr>\n    <tr>\n      <th>H</th>\n      <td>121</td>\n      <td>93</td>\n      <td>99</td>\n    </tr>\n    <tr>\n      <th>K</th>\n      <td>87</td>\n      <td>89</td>\n      <td>116</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 139,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cond = df.Python > 80  # 将Python大于80分的成绩获取\n",
    "df[cond]"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 140,
   "outputs": [
    {
     "data": {
      "text/plain": "   Python  Math   En\nA      41    89  150\nB     131   107  113\nC     105   110   85\nD     120   107  106\nH     121    93   99\nK      87    89  116",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Python</th>\n      <th>Math</th>\n      <th>En</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>A</th>\n      <td>41</td>\n      <td>89</td>\n      <td>150</td>\n    </tr>\n    <tr>\n      <th>B</th>\n      <td>131</td>\n      <td>107</td>\n      <td>113</td>\n    </tr>\n    <tr>\n      <th>C</th>\n      <td>105</td>\n      <td>110</td>\n      <td>85</td>\n    </tr>\n    <tr>\n      <th>D</th>\n      <td>120</td>\n      <td>107</td>\n      <td>106</td>\n    </tr>\n    <tr>\n      <th>H</th>\n      <td>121</td>\n      <td>93</td>\n      <td>99</td>\n    </tr>\n    <tr>\n      <th>K</th>\n      <td>87</td>\n      <td>89</td>\n      <td>116</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 140,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cond = df.mean(axis=1) > 75  # 平均分大于75，优秀，筛选出来\n",
    "df[cond]"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 141,
   "outputs": [
    {
     "data": {
      "text/plain": "   Python  Math   En\nB     131   107  113\nC     105   110   85\nD     120   107  106\nH     121    93   99\nK      87    89  116",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Python</th>\n      <th>Math</th>\n      <th>En</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>B</th>\n      <td>131</td>\n      <td>107</td>\n      <td>113</td>\n    </tr>\n    <tr>\n      <th>C</th>\n      <td>105</td>\n      <td>110</td>\n      <td>85</td>\n    </tr>\n    <tr>\n      <th>D</th>\n      <td>120</td>\n      <td>107</td>\n      <td>106</td>\n    </tr>\n    <tr>\n      <th>H</th>\n      <td>121</td>\n      <td>93</td>\n      <td>99</td>\n    </tr>\n    <tr>\n      <th>K</th>\n      <td>87</td>\n      <td>89</td>\n      <td>116</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 141,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cond = (df.Python > 70) & (df.Math > 70)\n",
    "df[cond]"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 142,
   "outputs": [
    {
     "data": {
      "text/plain": "   Python  Math   En\nC     105   110   85\nE      42    28   41\nH     121    93   99\nK      87    89  116",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Python</th>\n      <th>Math</th>\n      <th>En</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>C</th>\n      <td>105</td>\n      <td>110</td>\n      <td>85</td>\n    </tr>\n    <tr>\n      <th>E</th>\n      <td>42</td>\n      <td>28</td>\n      <td>41</td>\n    </tr>\n    <tr>\n      <th>H</th>\n      <td>121</td>\n      <td>93</td>\n      <td>99</td>\n    </tr>\n    <tr>\n      <th>K</th>\n      <td>87</td>\n      <td>89</td>\n      <td>116</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 142,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cond = df.index.isin([\"C\", \"E\", \"H\", \"K\"])  # 判断数据是否在数组中\n",
    "df[cond]  # 删选出来了符合条件的数据"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 143,
   "outputs": [
    {
     "data": {
      "text/plain": "   Python  Math   En\nA      60    89  150\nB     131   107  113\nC     105   110   85\nD     120   107  106\nE      60    60   60\nF      64    60   60\nH     121    93   99\nI      60    83   70\nJ      60    80   60\nK      87    89  116",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Python</th>\n      <th>Math</th>\n      <th>En</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>A</th>\n      <td>60</td>\n      <td>89</td>\n      <td>150</td>\n    </tr>\n    <tr>\n      <th>B</th>\n      <td>131</td>\n      <td>107</td>\n      <td>113</td>\n    </tr>\n    <tr>\n      <th>C</th>\n      <td>105</td>\n      <td>110</td>\n      <td>85</td>\n    </tr>\n    <tr>\n      <th>D</th>\n      <td>120</td>\n      <td>107</td>\n      <td>106</td>\n    </tr>\n    <tr>\n      <th>E</th>\n      <td>60</td>\n      <td>60</td>\n      <td>60</td>\n    </tr>\n    <tr>\n      <th>F</th>\n      <td>64</td>\n      <td>60</td>\n      <td>60</td>\n    </tr>\n    <tr>\n      <th>H</th>\n      <td>121</td>\n      <td>93</td>\n      <td>99</td>\n    </tr>\n    <tr>\n      <th>I</th>\n      <td>60</td>\n      <td>83</td>\n      <td>70</td>\n    </tr>\n    <tr>\n      <th>J</th>\n      <td>60</td>\n      <td>80</td>\n      <td>60</td>\n    </tr>\n    <tr>\n      <th>K</th>\n      <td>87</td>\n      <td>89</td>\n      <td>116</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 143,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cond = df < 60\n",
    "df[cond] = 60  # where 条件操作，符合这条件值，修改，不符合，不改变\n",
    "df"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## 高级索引"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "### loc 标签索引\n",
    "DataFrame 不能直接切片，可以通过loc来做切片\n",
    "loc是基于标签名的索引，也就是我们自定义的索引名\n",
    "标签，就是行索引 location = loc 位置"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 132,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "b    1\n",
      "c    2\n",
      "d    3\n",
      "dtype: int64\n"
     ]
    }
   ],
   "source": [
    "# Series\n",
    "print(ser_obj['b':'d'])"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "print(ser_obj.loc['b':'d'])"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 136,
   "outputs": [
    {
     "data": {
      "text/plain": "          a         b         c         d\n0  0.203998 -0.218377  0.431281  0.488778\n1  1.061244 -0.077600 -1.745808  0.987524\n2  0.015731  1.262258 -0.824925 -0.474100\n3 -1.239724 -0.439741 -0.463484  0.912487\n4 -0.366651 -1.382506 -0.319084  1.042559",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>a</th>\n      <th>b</th>\n      <th>c</th>\n      <th>d</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>0.203998</td>\n      <td>-0.218377</td>\n      <td>0.431281</td>\n      <td>0.488778</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>1.061244</td>\n      <td>-0.077600</td>\n      <td>-1.745808</td>\n      <td>0.987524</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>0.015731</td>\n      <td>1.262258</td>\n      <td>-0.824925</td>\n      <td>-0.474100</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>-1.239724</td>\n      <td>-0.439741</td>\n      <td>-0.463484</td>\n      <td>0.912487</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>-0.366651</td>\n      <td>-1.382506</td>\n      <td>-0.319084</td>\n      <td>1.042559</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 136,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# DataFrame\n",
    "df_obj"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 137,
   "outputs": [
    {
     "data": {
      "text/plain": "a    1.061244\nb   -0.077600\nc   -1.745808\nd    0.987524\nName: 1, dtype: float64"
     },
     "execution_count": 137,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_obj.loc[1]"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "outputs": [
    {
     "data": {
      "text/plain": "0   -2.102618\n1    1.665924\n2   -0.146991\n3   -0.691482\n4    2.083532\nName: a, dtype: float64"
     },
     "execution_count": 127,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_obj['a']"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 128,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0   -2.102618\n",
      "1    1.665924\n",
      "2   -0.146991\n",
      "Name: a, dtype: float64\n"
     ]
    }
   ],
   "source": [
    "# 第一个参数索引行，第二个参数是列\n",
    "print(df_obj.loc[0:2, 'a'])"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "### iloc 位置索引\n",
    "作用和loc一样，不过是基于索引编号来索引"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 129,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "b    1\n",
      "c    2\n",
      "dtype: int64\n"
     ]
    }
   ],
   "source": [
    "# Series\n",
    "print(ser_obj[1:3])"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "b    1\n",
      "c    2\n",
      "dtype: int64\n"
     ]
    }
   ],
   "source": [
    "print(ser_obj.iloc[1:3])"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 131,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0   -2.102618\n",
      "1    1.665924\n",
      "Name: a, dtype: float64\n"
     ]
    }
   ],
   "source": [
    "# DataFrame\n",
    "print(df_obj.iloc[0:2, 0]) # 注意和df_obj.loc[0:2, 'a']的区别，使用Loc切片包含尾部下标数据"
   ],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.20"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
